package com.java46.carera.candidate.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java46.carera.base.entity.Candidate;
import com.java46.carera.base.entity.JsonResult;
import com.java46.carera.base.exception.BusinessException;
import com.java46.carera.base.mapper.CandidateMapper;
import com.java46.carera.base.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ReservationRecordService
 * @Description 招聘后台Service
 * @Author TriggerWu
 * @Date 2018/8/28 18:56
 * @Vcrsion 1.0
 **/
@Service
public class CandidateService {
    @Autowired
    private CandidateMapper candidateMapper;

    /**
     * 模糊查询所有招聘记录
     * @param keyword
     * @param pageNum
     * @return
     */
    public JsonResult queryAll(String keyword, Integer pageNum){
        PageHelper.startPage(pageNum,5);
        List<Candidate> reservationRecords = candidateMapper.selectAllBySearch(keyword);
        PageInfo<Candidate> pages = new PageInfo<>(reservationRecords);
        return JsonUtil.setJsonResult(true,"查询成功！",pages);
    }
    /**
     * 修改招聘审核处理状态
     * @param canid
     * @return
     */
    public JsonResult updateByStatus(Integer canid){
        if(canid == null){
            throw new BusinessException("缺少修改的必要参数！");
        }
        candidateMapper.updateByStatus(canid);
        return JsonUtil.setJsonResult(true,"修改成功！",null);
    }
    /**
     * 删除信息
     * @param canId
     * @return
     */
    public JsonResult deleteById(Integer canId){
        if(canId == null){
            throw new BusinessException("缺少修改的必要参数！");
        }
        candidateMapper.deleteByPrimaryKey(canId);
        return JsonUtil.setJsonResult(true,"修改成功！",null);
    }
}
